#include "UniformBufferLoader.h"

namespace SEngine
{
    UniformBufferLoader & UniformBufferLoader::AddBlock(const std::string &name, size_t size)
    {
        m_blocks.emplace(name, UniformBuffer::Block{m_curOffset, size});
        m_bufferSize = m_curOffset + size;
        m_curOffset += ((size_t)(size / 16) + (size_t)(size % 16 != 0)) * 16; 
        return *this;
    }
    
    std::unique_ptr<UniformBuffer> UniformBufferLoader::CreateUniformBuffer(std::unique_ptr<IDrive> && drive, const std::string & name, uint32_t bindPoint)
    {
        auto ubo = std::make_unique<UniformBuffer>(std::move(drive), m_bufferSize, name, bindPoint);
        ubo->m_blocks = std::move(m_blocks);
        return ubo;
    }
} // namespace SEngine
